<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/layui.css}" rel="stylesheet" >
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>
    <link th:href="@{/css/checkbox.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/ry-ui.min.css}" rel="stylesheet"/>
    <!-- Data Tables -->
    <link th:href="@{/css/plugins/dataTables/dataTables.bootstrap.css}" rel="stylesheet">
    <link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
    <link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 select-info">
            <form id="user-form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list gd">
                    <ul>
                        <li>
                            出勤状态：<select id="status" name="status">
                            <option>所有</option>
                            <option >正常</option>
                            <option >迟到</option>
                            <option >旷工</option>
                        </select>
                        </li>
                        <li class="time">
                            <label>日期范围： </label>
                            <input type="text" class="form-control layer-date" id="start" autocomplete="off" placeholder="开始时间" name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text"  class="form-control layer-date" id="end" autocomplete="off" placeholder="结束时间" name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searchAttend()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-info table-striped">
            <table id="tb_departments">
            </table>
        </div>
    </div>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<!-- bootstrap-table 表格插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
<!-- jquery-export 表格导出插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/tableExport.js}"></script>
<!-- Data Tables -->
<script th:src="@{/js/plugins/dataTables/jquery.dataTables.js}"></script>
<script th:src="@{/js/plugins/dataTables/dataTables.bootstrap.js}"></script>
<script th:src="@{/js/plugins/jeditable/jquery.jeditable.js}"></script>
<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ajax/libs/layui/layui.js}"></script>
<script th:src="@{/ruoyi/js/common.js?v=2.2.0}"></script>
<script th:src="@{/ruoyi/js/yuyu-ui.min.js?v=2.2.0}"></script>
<script>
    $(function () {

        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();
        //2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();

    });
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_departments').bootstrapTable({
                url: '/attend/list',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortName: "id",
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                // clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [ {
                    field: 'id',
                    title: '编号',
                    sortable: true
                },{
                    field: 'attendDate',
                    title: '考勤日期',
                    formatter: function(e ,value, row, index){
                        var  actions = [];
                        actions.push('  <div type="text">'+formattimeYMD(value.attendDate)+'</div>')
                        return actions.join('');
                    }
                }, {
                    field: 'attendWeek',
                    title: '星期'
                }, {
                    field: 'attendMorning',
                    title: '早打卡',
                    formatter: function(e ,value, row, index){
                        var  actions = [];
                        actions.push('  <div type="text">'+formattimeHMS(value.attendMorning)+'</div>')
                        return actions.join('');
                    }
                }, {
                    field: 'attendEvening',
                    title: '晚打卡',
                    formatter: function(e ,value, row, index){
                        var  actions = [];
                        actions.push('  <div type="text">'+formattimeHMS(value.attendEvening)+'</div>')
                        return actions.join('');
                    }
                }, {
                    field: 'absenceTime',
                    title: '缺勤时长(分钟)'
                }, {
                    field: 'attendStatus',
                    title: '考勤状态',
                    formatter: function(e ,value, row, index){
                        var  actions = [];
                        if (value.attendStatus == 1){
                            actions.push('<div style="color: green">正常</div>');
                        }else if (value.attendStatus == 2){
                            actions.push('<div style="color: orange" >迟到</div>');
                        }else {
                            actions.push('<div style="color: red" >旷工</div>');
                        }
                        return actions.join('');
                    }
                }, {
                    field: 'Button',
                    title: '操作',
                    events: operateEvents,
                    formatter: Operate
                }
                    ,],
                showExport:true,              //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
                exportDataType: "all",              //basic', 'all', 'selected'.
                exportTypes:[ 'excel','doc','xlsx','csv', 'txt', 'sql' ],	    //导出类型
                // exportButton: $('#btn_export'),     //为按钮btn_export  绑定导出事件  自定义导出按钮(可以不用)
                exportOptions:{
                    ignoreColumn: [0,8],            //忽略某一列的索引
                    fileName: '员工信息表',              //文件名称设置
                    worksheetName: 'Sheet1',          //表格工作区名称
                    tableName: '数据表',
                    excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                    //onMsoNumberFormat: DoOnMsoNumberFormat
                }
            });
        };
        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,   //页面大小
                offset: params.offset,  //页码
                departmentname: $("#txt_search_departmentname").val(),
                statu: $("#txt_search_statu").val(),
                search:params.search
            };
            return temp;
        };
        return oTableInit;
    };
    window.operateEvents = {
        "click #TableEditor": function (e ,value, row, index) {
            var url = '/reattend/'+row.id;
            $.modal.open("补签申请", url, '800', '480');
        }};
    function Operate(e ,value, row, index){
        if (value.attendStatus==2){
            return [
                '<button id="TableEditor" type="button" class="btn btn-info btn-xs">补签</button>'
            ].join("")
        }else {
            return [].join("")
        }
    }
    function formattimeYMD(timestamp) {
        var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' '
        return Y+M+D;
    }
    function formattimeHMS(timestamp) {
        var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        return h+m+s;
    }
    var ButtonInit = function () {
        var oInit = new Object();
        var postdata = {};
        oInit.Init = function () {
            //初始化页面上面的按钮事件
        };
        return oInit;
    };
    $('.dataTables-example').dataTable({
        // "columnDefs": [{"orderable": false, "targets": 1}]
        ordering: false
    });
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD hh:mm:ss',
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: true,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
            //获取日期的内容
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: true,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);

    function searchAttend() {
        var startDate = $("input[name='params[beginTime]']").val();
        var endDate = $("input[name='params[endTime]']").val();
           if ($("#status").val()=="所有"){
              var attendStatus=0;
           }else if ($("#status").val()=="正常"){
               var attendStatus=1;
           }else if ($("#status").val()=="迟到"){
               var attendStatus=2;
           }else {
               var attendStatus=3;
           }
        var json= {
           "startDate": startDate,
            "endDate":endDate,
            "attendStatus":attendStatus
        };
        $("#tb_departments").bootstrapTable('refresh', {
            url: "/attend/search", //重设数据来源
            query: json//传到后台的参数
        });
    }
</script>
</body>
</html>